package com.seed.dev.web;

import com.seed.application.web.impl.DefaultWebContext;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class DevWebContext extends DefaultWebContext {

    public DevWebContext(HttpServletRequest request) {
        super(request);
    }

    @Override
    public String getSeedName() {
        HttpServletRequest request = getRequest();
        String uri = request.getRequestURI();
        uri = uri.substring(1);
        String[] items = uri.split("/");
        int len = items.length;
        if(len == 2 || len == 3) return items[0];

        return null;
    }

    @Override
    public String getActionName() {
        HttpServletRequest request = getRequest();
        String uri = request.getRequestURI();
        uri = uri.substring(1);
        String[] items = uri.split("/");

        return items[items.length == 1 ? 0 : 1];
    }
}
